Minimizing redundant parentheses for filters?

Is there a way to minimize redundant parentheses for filters created with DXL?

Filters share a lot of similarities with creating SQL for databases. Once you get beyond a the most simple queries, the logic may not work as intended at first.

The best tips are to be careful and lay out the SQL in consistent, neat, logical way.

With DXL, one can not enter hand-crafted SQL text, but DXL can be used to build up filters.

I've had success with writing out the logic in a structured indented way (as I would with SQL) and then building up the filters in an orderly way.

My frustration is for each condition added to a filter, new parentheses are added whether needed or not. After adding a filter of complexity, there are so many extra parentheses it is very difficult to verify the logic by inspection.

QUESTION
Is there some means getting logic into a filter without parentheses following each addition. See the below:

void makeAFilter(string fullModuleString, string viewName, Filter myFilter) { 
    Module m = edit(fullModuleString, true);
    set(m, myFilter);
    save(m, view(viewName));
} 
 
void testMakeFilter() {
    Module m = current Module;
    string targetModuleFullName = fullName(m) "_test"
    Filter myFilter = (attribute  "Absolute Number" > "1") //-
                   && (attribute "Absolute Number" > "5000") //-
                   && (attribute "Absolute Number" > "3") //-
                   && (attribute "Absolute Number" > "4") //-
                   && (attribute "Absolute Number" > "5") ; 
    makeAFilter(targetModuleFullName, "myEvalView7", myFilter); 
 
// Call it:
testMakeFilter();

 


RAW:

((((Absolute Number > 1) AND (Absolute Number > 5000)) AND (Absolute Number > 3)) AND (Absolute Number > 4)) AND (Absolute Number > 5)

STRUCTURE:

 

 

( -- BEGIN group 1
  ( -- BEGIN group 1.1
    ( -- BEGIN group 1.1.1
      (Absolute Number > 1) 
        AND 
      (Absolute Number > 5000)
    ) -- END group 1.1.1
      AND 
    (Absolute Number > 3)
  ) -- END group 1.1
    AND 
  (Absolute Number > 4)
) -- END -- group 1
  AND 
(Absolute Number > 5)


ANOTHER WAY TO LOOK AT IT:
cond1 = (Absolute Number > 1)
cond2 = (Absolute Number > 5000)
cond3 = (Absolute Number > 3)
cond4 = (Absolute Number > 4)
cond5 = (Absolute Number > 5)

 

 

( -- BEGIN Group 1 
  ( -- BEGIN Group 1.1
    ( -- BEGIN Group 1.1.1
      cond1 
        AND 
      cond2
    ) -- END Group 1.1.1
      AND 
    cond3
  ) -- BEGIN Group 1.1
    AND 
  cond4
) -- END Group 1
  AND 
cond5


HOPE
Is there any clever way to create a filter that will have simply?:
(Absolute Number > 1) AND (Absolute Number > 5000) AND (Absolute Number > 3) AND (Absolute Number > 4) AND (Absolute Number > 5)

WHY?
This is a simple, silly example, but when AND OR and NOT get in the mix, I need all the help I can get.

ALTERNATIVE
If there is no way around the redundant parentheses issue, I suppose one could write a redundant parentheses remover as an aid in analyzing filters that have gone wrong.

 


SystemAdmin - Wed May 26 13:00:40 EDT 2010

Re: Minimizing redundant parentheses for filters?
Mathias Mamsch - Wed May 26 14:59:16 EDT 2010

Short answer: There is no such thing in DXL. Filters use binary (two parameters) operations, so they can be evaluated easier and quicker. You combine filters using the DXL operators (which are binary or unary (=one parameter)). So you only have the option the remove the redundant braces. For this you have to parse the content of each brace and find out the operator, then maybe put them in a tree-like structure, which you can then postprocess and convert back to a string. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Minimizing redundant parentheses for filters?
SystemAdmin - Thu May 27 09:32:57 EDT 2010

Mathias Mamsch - Wed May 26 14:59:16 EDT 2010
Short answer: There is no such thing in DXL. Filters use binary (two parameters) operations, so they can be evaluated easier and quicker. You combine filters using the DXL operators (which are binary or unary (=one parameter)). So you only have the option the remove the redundant braces. For this you have to parse the content of each brace and find out the operator, then maybe put them in a tree-like structure, which you can then postprocess and convert back to a string. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Thanks for the informative reply. Based on the both (1) the DXL perms I saw and (2) the structure of the results -- I was afraid the filters were buildups of binary operations (as you revealed).

The good news is I can still get the job done. The bad news is filters are a bit harder than SQL to verify correctness by visual inspection.

Re: Minimizing redundant parentheses for filters?
Mathias Mamsch - Thu May 27 09:46:46 EDT 2010

SystemAdmin - Thu May 27 09:32:57 EDT 2010
Thanks for the informative reply. Based on the both (1) the DXL perms I saw and (2) the structure of the results -- I was afraid the filters were buildups of binary operations (as you revealed).

The good news is I can still get the job done. The bad news is filters are a bit harder than SQL to verify correctness by visual inspection.

I find the thought of relying on complex filters for whatever reason a bit scary. If the information in your modules is so complex (like different versions of an object, variants/configurations, etc.), that you have to put a complex filter in place to get a valid subset of information and the information is so important that you need to review those filters to make sure they are correct - my suspicion would be that you might be facing some more problems with the "All-Information-In-One-Module" approach (been there, done that) and that it could be worth to think about different approaches. Just a hunch ... Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Minimizing redundant parentheses for filters?
SystemAdmin - Thu May 27 10:51:36 EDT 2010

Mathias Mamsch - Thu May 27 09:46:46 EDT 2010
I find the thought of relying on complex filters for whatever reason a bit scary. If the information in your modules is so complex (like different versions of an object, variants/configurations, etc.), that you have to put a complex filter in place to get a valid subset of information and the information is so important that you need to review those filters to make sure they are correct - my suspicion would be that you might be facing some more problems with the "All-Information-In-One-Module" approach (been there, done that) and that it could be worth to think about different approaches. Just a hunch ... Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Your hunch about the "All-Information-In-One-Module" approach is not too far off from the mark. It is not "All Information". Rather it is test procedures. The "All-Information-In-One-Module" approach was handed down from the top. I can't change it. To me, the next best thing is to have a GUI assisted filter with limited amount of "filtering types". This way if I get the filters working right for each supported filter type, they all should work.